package cn.tedu.egarticle0811.base.Interceptor;

import cn.tedu.egarticle0811.pojo.vo.UserVO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

@Slf4j
public class LonginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("preHandle拦截登录...");
        HttpSession session = request.getSession();
        UserVO userVO = (UserVO) session.getAttribute("user");
        if (userVO != null) {
            log.debug("用户已登录，放行...");
            return true;
        } else {
            log.debug("用户未登录，拦截...");
            throw new RuntimeException("用户未登录！");
        }
    }
}
